package com.nexfra.bbssys.common.utils;

public class Paginator {
	private int pageNo = 1; // 현재 페이지 번호* 
	private int groupNo = 0; // 현재 그룹번호 
	private int pageSize = 10; // 한페이지에 보이는 게시물수 *
	private int groupSize = 5; // 그룹수(10이라면 [1]..[10]까지) *
	private long totCnt = 0; // 게시물의 총수 *
	private int curNum = 0; 
	private long startRow = 0; // 현재페이지의 시작번호 * sql검색조건으로 들어감
	private long endRow = 0; // 현재페이지의 끝번호 * sql검색조건으로 들어감
	private int startPage = 0; // 현재그룹의 시작 페이지번호
	private int endPage = 0; // 현재그룹의 마지막 페이지번호
	private int totalPageCnt = 0; // 총페이지수
	private int totalPageGroupCnt = 0; // 총그룹수
	private int nextGroupPage = 0; // 이전그룹의 페이지번호값
	private int prevGroupPage = 0; // 다음그룹의 페이지번호값
	
	public Paginator(int pageNo, int pageSize, int groupSize, long totCnt) {
		this.pageSize = pageSize;
		this.groupSize = groupSize;
		this.totCnt = totCnt;
		this.pageNo = pageNo;
	}
	
	public Paginator(int pageNo, long totCnt) {
		this.totCnt = totCnt;
		this.pageNo = pageNo;
	}

	public void setPageProperties() {		
		this.groupNo = this.pageNo / this.groupSize + (this.pageNo % this.groupSize == 0 ? 0 : 1);
		this.prevGroupPage = (this.groupNo - 2 ) * this.groupSize + 1;
		this.nextGroupPage = this.groupNo * this.groupSize + 1;

		this.totalPageCnt = (int)((this.totCnt / this.pageSize) +  (this.totCnt % this.pageSize == 0 ? 0 : 1));
		this.totalPageGroupCnt = this.totalPageCnt / this.groupSize + ( this.totalPageCnt % this.groupSize == 0 ? 0 : 1 );
		
		this.startRow = (this.pageNo - 1) * this.pageSize + 1 ;
		this.endRow = this.pageNo * this.pageSize;	
		if(endRow > totCnt) endRow = totCnt;
		
		this.startPage = (this.groupNo - 1 ) * this.groupSize + 1;
		this.endPage = this.startPage + this.groupSize - 1;
		
		if(this.endPage > this.totalPageCnt)
			this.endPage = this.totalPageCnt;		
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;	
	}

	public int getPageNo() {
		return pageNo;
	}

	public int getGroupNo() {
		return groupNo;
	}

	public void setGroupNo(int groupNo) {
		this.groupNo = groupNo;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getGroupSize() {
		return groupSize;
	}

	public void setGroupSize(int groupSize) {
		this.groupSize = groupSize;
	}

	public long getTotCnt() {
		return totCnt;
	}

	public void setTotCnt(long totCnt) {
		this.totCnt = totCnt;
	}

	public int getCurNum() {
		return curNum;
	}

	public void setCurNum(int curNum) {
		this.curNum = curNum;
	}

	public long getStartRow() {
		return startRow;
	}

	public void setStartRow(int startRow) {
		this.startRow = startRow;
	}

	public long getEndRow() {
		return endRow;
	}

	public void setEndRow(int endRow) {
		this.endRow = endRow;
	}

	public int getStartPage() {
		return startPage;
	}

	public void setStartPage(int startPage) {
		this.startPage = startPage;
	}

	public int getEndPage() {
		return endPage;
	}

	public void setEndPage(int endPage) {
		this.endPage = endPage;
	}

	public int getTotalPageCnt() {
		return totalPageCnt;
	}

	public void setTotalPageCnt(int totalPageCnt) {
		this.totalPageCnt = totalPageCnt;
	}

	public int getTotalPageGroupCnt() {
		return totalPageGroupCnt;
	}

	public void setTotalPageGroupCnt(int totalPageGroupCnt) {
		this.totalPageGroupCnt = totalPageGroupCnt;
	}

	public int getNextGroupPage() {
		return nextGroupPage;
	}

	public void setNextGroupPage(int nextGroupPage) {
		this.nextGroupPage = nextGroupPage;
	}

	public int getPrevGroupPage() {
		return prevGroupPage;
	}

	public void setPrevGroupPage(int prevGroupPage) {
		this.prevGroupPage = prevGroupPage;
	}
	
}
